import React from 'react';
import axios from 'axios';

class Product extends React.Component {
  constructor(props) {
    super(props)
    this.state = {
      products: []
    }
  }
  render() {
    return (
      <div>
        <h1>产品列表</h1>
        <ul>
          {
            this.state.products.map((ele,index) => {
              return <li key={index}> {ele.name} </li>
            })
          }
        </ul>
      </div>
    )
  }
  componentDidMount() {
    axios.get("/api/test/products").then(res => {
      console.log(res)
      this.setState({products: res.data})
    }).catch(err => {
      console.log(err)
    })
  }
}

export default Product;